/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-06-01
 * Time: 23:58
 */
public class InsertSort {
    public static void main(String[] args) {
        int[] array = {1,4,2,9,6,7};
        insertSort(array);
        for(int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
    }
    
    public static void insertSort(int[] array) {
        for(int i = 1; i < array.length; i++) {
            int tmp = array[i];
            int j = i-1;
            for(; j >= 0; j--) {
                if(array[j] > tmp) {
                    array[j+1] = array[j];
                }else {
                    //array[j+1] = tmp;
                    break;
                }
            }
            array[j+1] = tmp;
        }
    }
}
